<template>
	<div class="body">
		<div style="width: 100%; height: 100px">
			<a-row :gutter="[16, 8]">
				<a-col :span="4">
					<a-space>
						<a-button icon="left" @click.stop="goPrev" />
						<a-date-picker style="width: 130px" v-model:value="currentMonth" placeholder="选择日期"
							:allowClear="false" @change="onChangeDate" />
						<a-button icon="right" @click.stop="goNext" />
					</a-space>
				</a-col>
				<a-col :span="4">
					<span>姓名：</span>
					<a-input v-model="queryParam.realname" placeholder="请输入姓名" style="width: 180px" />
				</a-col>
				<a-col :span="4">
					<span>工号：</span>
					<a-input v-model="queryParam.workNo" placeholder="请输入工号" style="width: 180px" />
				</a-col>
				<!--        <a-col :span="4">
				-->
				<!--          <span>时间：</span>-->
				<!--          <a-date-picker v-model="time" style="width: 180px"/>-->
				<!--        </a-col>-->
				<a-col :span="4">
					<span>车间：</span>
					<j-multi-select-tag placeholder="请选择车间" v-model="queryParam.workshop" dictCode="workshop"
						style="width: 180px" />
				</a-col>
				<a-col :span="4">
					<span>班次：</span>
					<j-dict-select-tag placeholder="请选择班次" v-model="queryParam.shift" dictCode="shift"
						style="width: 180px" />
				</a-col>
				<a-col :span="4">
					<span>品种：</span>
					<j-dict-select-tag placeholder="请选择品种" v-model="queryParam.productType"
						dictCode="crm_product_type_spun_yarn,product_type,id" style="width: 180px" />
				</a-col>
				<a-col :span="4">
					<span>工种：</span>
					<j-dict-select-tag placeholder="请选择品种" v-model="queryParam.workType" dictCode="work_type"
						style="width: 180px" />
				</a-col>
			</a-row>
			<div style="margin-top: 20px;">
				<a-space style="float: right;">
					<a-button @click="handleExportXls('甲班')" type="default" icon="export">导出报表</a-button>
					<a-button @click="handleSearch()" type="primary">搜索</a-button>
					<a-button @click="handleAdd" type="primary">新增</a-button>
					<a-button type="primary" @click="generateSalary">生成报表</a-button>
					<!-- <a-button>导出报表</a-button> -->
					<a-button @click="ExportLengthReport('细纱长度报表')" style="width: 100%">导出长度报表</a-button>
					<!-- <a-button type="primary">自选生产薪资报表</a-button> -->
				</a-space>
			</div>
		</div>
		<div style="margin-top: 15px;">
			<a-table :columns="columns" rowKey="id" :data-source="dataSource" :scroll="{ x: 6500 }"
				:pagination="ipagination" :loading="loading"
				:rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
				@change="handleTableChange">
				<!-- 操作 -->
				<a-space slot="action" slot-scope="text, record">
					<template>
						<a-button style="padding: 0px" type="link" icon="edit" @click="handleEdit(record)">编辑</a-button>
						<a-popconfirm title="确认要删除吗?" @confirm="() => handleDelete(record.id)">
							<a-button style="color: red; padding: 0px" type="link" icon="delete">删除</a-button>
						</a-popconfirm>
					</template>
				</a-space>
			</a-table>
		</div>
		<jia-ban-modal ref="modalForm" @ok="modalFormOk"></jia-ban-modal>
	</div>
</template>

<script>
	import {
		downFile
	} from '@/api/manage'
	import {
		JeecgListMixin
	} from '@/mixins/JeecgListMixin'
	import JiaBanModal from './modules/JiaBanModal'
	import {
		copyYesterdayDailyPlan,
		getGenerateSalary
	} from '../../../api/customApi'
	import moment from 'moment'
	const path = '/crm_salary_excel_spun_yarn/crmSalaryExcelSpunYarn'
	export default {
		mixins: [JeecgListMixin],
		components: {
			JiaBanModal
		},
		data() {
			return {
				currentMonth: moment(),
				columns,
				queryParam: {
					planTime: moment().format('YYYY-MM-DD'),
					shift: 1
				},
				url: {
					list: path + '/list',
					delete: path + '/delete',
					deleteBatch: path + '/deleteBatch',
					exportXlsUrl: '/crm_salary_excel_spun_yarn/crmSalaryExcelSpunYarn/exportExcel',
					exportLengthXlsUrl: '/crm_salary_excel_spun_yarn/crmSalaryExcelSpunYarn/exportLengthExcel'
				}
			}
		},
		methods: {
			goPrev() {
				var newMonth = moment(this.currentMonth).subtract(1, 'day')
				this.currentMonth = newMonth
				this.queryParam.planTime = this.currentMonth.format('YYYY-MM-DD')
				this.queryParam.shift = 1
				this.searchQuery()
			},
			goNext() {
				var newMonth = moment(this.currentMonth).add(1, 'day')
				this.currentMonth = newMonth
				this.queryParam.planTime = this.currentMonth.format('YYYY-MM-DD')
				this.queryParam.shift = 1
				this.searchQuery()
			},
			onChangeDate(date, dateString) {
				this.queryParam.planTime = dateString
				this.searchQuery()
			},
			changeObject() {},
			refresh() {
				this.searchQuery()
			},
			handleSearch() {
				this.searchQuery()
				this.visible = false
			},
			handleCancel() {
				this.visible = false
			},
			handleReset() {
				this.searchReset()
			},
			add() {
				this.visable1 = true
			},
			detail(record) {},
			onChangePage(e) {
				this.ipagination.current = e
				this.loadData()
			},
			generateSalary() {
				let query = {
					// planTime:this.currentMonth
					planTime: this.queryParam.planTime,
					shift: 1
				}
				getGenerateSalary(query).then(res => {
					if (res.success) {
						this.$message.success('生成成功')
						this.searchQuery()
					}
				})
			},
			btnImport() {},
			btnExport() {},
			ExportLengthReport(fileName) {
				if (!fileName || typeof fileName != 'string') {
					fileName = '导出文件'
				}
				let param = this.getQueryParams()
				if (this.selectedRowKeys && this.selectedRowKeys.length > 0) {
					param['selections'] = this.selectedRowKeys.join(',')
				}
				console.log('导出参数', param)
				downFile(this.url.exportLengthXlsUrl, param).then(data => {
					if (!data) {
						this.$message.warning('文件下载失败')
						return
					}
					if (typeof window.navigator.msSaveBlob !== 'undefined') {
						window.navigator.msSaveBlob(new Blob([data], {
							type: 'application/vnd.ms-excel'
						}), fileName + '.xls')
					} else {
						let url = window.URL.createObjectURL(new Blob([data], {
							type: 'application/vnd.ms-excel'
						}))
						let link = document.createElement('a')
						link.style.display = 'none'
						link.href = url
						link.setAttribute('download', fileName + '.xls')
						document.body.appendChild(link)
						link.click()
						document.body.removeChild(link) //下载完成移除元素
						window.URL.revokeObjectURL(url) //释放掉blob对象
					}
				})
			}
		}
	}

	const columns = [{
			title: '日期',
			width: 200,
			dataIndex: 'planTime',
			key: 'planTime',
			fixed: 'left'
		},
		{
			title: '车间',
			width: 100,
			dataIndex: 'workshop',
			key: 'workshop',
			fixed: 'left'
		},
		{
			title: '班次',
			width: 100,
			dataIndex: 'shift_dictText',
			key: 'shift',
			fixed: 'left'
		},
		{
			title: '上班时间',
			width: 100,
			dataIndex: 'workHours',
			key: 'workHours',
			fixed: 'left'
		},
		{
			title: '机台时间',
			width: 100,
			dataIndex: 'machineHours',
			key: 'machineHours',
			fixed: 'left'
		},
		{
			title: '机台',
			width: 100,
			dataIndex: 'deviceNo',
			key: 'deviceNo',
			fixed: 'left'
		},
		{
			title: '工号',
			dataIndex: 'workNo',
			key: 'workNo',
			width: 150
		},
		{
			title: '姓名',
			dataIndex: 'realname',
			key: 'realname',
			width: 150
		},
		// { title: '工号-挡车', dataIndex: 'workNoBlockingCar', key: 'workNoBlockingCar', width: 150 },
		// { title: '姓名-挡车', dataIndex: 'nameBlockingCar', key: 'nameBlockingCar', width: 150 },
		// { title: '工号-落纱', dataIndex: 'workNoDoff', key: 'workNoDoff', width: 150 },
		// { title: '姓名-落纱', dataIndex: 'nameDoff', key: 'nameDoff', width: 150 },
		// { title: '工号-摆管', dataIndex: 'workNoSwingPipe', key: 'workNoSwingPipe', width: 150 },
		// { title: '姓名-摆管', dataIndex: 'nameSwingPipe', key: 'nameSwingPipe', width: 150 },
		{
			title: '品种类别',
			dataIndex: 'productCategory',
			key: 'productCategory',
			width: 150
		},
		{
			title: '品种',
			dataIndex: 'productType_dictText',
			key: 'productType_dictText',
			width: 200
		},
		{
			title: '支数',
			dataIndex: 'productBranch',
			key: 'productBranch',
			width: 150
		},
		{
			title: '挡车机台系数',
			dataIndex: 'blockingCarMachineCoefficient',
			key: 'blockingCarMachineCoefficient',
			width: 150
		},
		{
			title: '挡车品种系数',
			dataIndex: 'blockingCarProductTypeCoefficient',
			key: 'blockingCarProductTypeCoefficient',
			width: 150
		},
		{
			title: '挡车单价系数',
			dataIndex: 'blockingCarUnitPriceCoefficient',
			key: 'blockingCarUnitPriceCoefficient',
			width: 150
		},
		{
			title: '挡车综合系数',
			dataIndex: 'blockingCarComprehensiveCoefficient',
			key: 'blockingCarComprehensiveCoefficient',
			width: 150
		},
		{
			title: '落纱机台系数',
			dataIndex: 'doffMachineCoefficient',
			key: 'doffMachineCoefficient',
			width: 150
		},
		{
			title: '落纱品种系数',
			dataIndex: 'doffProductTypeCoefficient',
			key: 'doffProductTypeCoefficient',
			width: 150
		},
		{
			title: '落纱单价系数',
			dataIndex: 'doffUnitPriceCoefficient',
			key: 'doffUnitPriceCoefficient',
			width: 150
		},
		{
			title: '落纱综合系数',
			dataIndex: 'doffComprehensiveCoefficient',
			key: 'doffComprehensiveCoefficient',
			width: 150
		},
		{
			title: '锭数',
			dataIndex: 'ingotsNum',
			key: 'ingotsNum',
			width: 150
		},
		{
			title: '定量',
			dataIndex: 'quantify',
			key: 'quantify',
			width: 150
		},
		{
			title: '8小时定额长度',
			dataIndex: 'fixedLengthEightHours',
			key: 'fixedLengthEightHours',
			width: 150
		},
		{
			title: '台数',
			dataIndex: 'machinesNum',
			key: 'machinesNum',
			width: 150
		},
		{
			title: '台数（8小时）',
			dataIndex: 'machinesNumEightHours',
			key: 'machinesNumEightHours',
			width: 150
		},
		{
			title: '挡车定额看台（台）',
			dataIndex: 'blockingCarFixedMachinesNum',
			key: 'blockingCarFixedMachinesNum',
			width: 200
		},
		{
			title: '落纱定额看台（台）',
			dataIndex: 'doffFixedMachinesNum',
			key: 'doffFixedMachinesNum',
			width: 200
		},
		{
			title: '挡车总看台率%',
			dataIndex: 'blockingCarTotalMachinesRate',
			key: 'blockingCarTotalMachinesRate',
			width: 150
		},
		{
			title: '落纱总看台率%',
			dataIndex: 'doffTotalMachinesRate',
			key: 'doffTotalMachinesRate',
			width: 150
		},
		{
			title: '落纱队别',
			dataIndex: 'doffTeam',
			key: 'doffTeam',
			width: 150
		},
		{
			title: '落纱队人数',
			dataIndex: 'doffTeamNum',
			key: 'doffTeamNum',
			width: 150
		},
		{
			title: '落纱个人数',
			dataIndex: 'doffPeopleNum',
			key: 'doffPeopleNum',
			width: 150
		},
		{
			title: '落纱数（次/台）',
			dataIndex: 'doffNum',
			key: 'doffNum',
			width: 150
		},
		{
			title: '台位换纱定数',
			dataIndex: 'machinesChangeYarnIngotsNum',
			key: 'machinesChangeYarnIngotsNum',
			width: 150
		},
		{
			title: '挡车工换纱锭数（锭/台）',
			dataIndex: 'blockingCarChangeYarnIngotsNum',
			key: 'blockingCarChangeYarnIngotsNum',
			width: 200
		},
		{
			title: '落纱工换纱锭数（锭/台）',
			dataIndex: 'doffChangeYarnIngotsNum',
			key: 'doffChangeYarnIngotsNum',
			width: 200
		},
		{
			title: '接班长度',
			dataIndex: 'takeoverLength',
			key: 'takeoverLength',
			width: 150
		},
		{
			title: '交班长度',
			dataIndex: 'handoverLength',
			key: 'handoverLength',
			width: 150
		},
		{
			title: '实际长度',
			dataIndex: 'realityLength',
			key: 'realityLength',
			width: 150
		},
		{
			title: '重量（kg）',
			dataIndex: 'weight',
			key: 'weight',
			width: 150
		},
		{
			title: '挡车单价（百米/元）',
			dataIndex: 'blockingCarUnitPrice',
			key: 'blockingCarUnitPrice',
			width: 200
		},
		{
			title: '落纱单价（元/落）',
			dataIndex: 'doffUnitPrice',
			key: 'doffUnitPrice',
			width: 150
		},
		{
			title: '换纱单价（元/落）',
			dataIndex: 'changeYarnUnitPrice',
			key: 'changeYarnUnitPrice',
			width: 150
		},
		{
			title: '落纱清洁单价（元/台）',
			dataIndex: 'doffCleanUnitPrice',
			key: 'doffCleanUnitPrice',
			width: 200
		},
		{
			title: '落纱产量单价（元/台）',
			dataIndex: 'doffProductionUnitPrice',
			key: 'doffProductionUnitPrice',
			width: 200
		},
		{
			title: '摆管单价（元/台）',
			dataIndex: 'swingPipeUnitPrice',
			key: 'swingPipeUnitPrice',
			width: 150
		},
		{
			title: '挡车工资（元）',
			dataIndex: 'blockingCarWages',
			key: 'blockingCarWages',
			width: 150
		},
		{
			title: '挡车换纱工资（元）',
			dataIndex: 'blockingCarChangeYarnWages',
			key: 'blockingCarChangeYarnWages',
			width: 200
		},
		{
			title: '挡车系数补扣',
			dataIndex: 'blockingCarCoefficientDeduction',
			key: 'blockingCarCoefficientDeduction',
			width: 150
		},
		{
			title: '挡车其它补贴',
			dataIndex: 'blockingCarOtherSubsidies',
			key: 'blockingCarOtherSubsidies',
			width: 150
		},
		{
			title: '挡车合计工资',
			dataIndex: 'blockingCarTotalWages',
			key: 'blockingCarTotalWages',
			width: 150
		},
		{
			title: '落纱台产量工资(元)',
			dataIndex: 'doffMachinesProductionWages',
			key: 'doffMachinesProductionWages',
			width: 200
		},
		{
			title: '落纱次数工资（元）',
			dataIndex: 'doffFrequencyWages',
			key: 'doffFrequencyWages',
			width: 200
		},
		{
			title: '落纱台系数补扣',
			dataIndex: 'doffMachinesCoefficientDeduction',
			key: 'doffMachinesCoefficientDeduction',
			width: 150
		},
		{
			title: '落纱次数个人工资（元）',
			dataIndex: 'doffFrequencyPersonalWages',
			key: 'doffFrequencyPersonalWages',
			width: 200
		},
		{
			title: '换纱工资（元）',
			dataIndex: 'changeYarnWages',
			key: 'changeYarnWages',
			width: 150
		},
		{
			title: '落纱清洁工资（元）',
			dataIndex: 'doffCleanWages',
			key: 'doffCleanWages',
			width: 200
		},
		{
			title: '落纱个人产量工资（元）',
			dataIndex: 'doffPersonalProductionWages',
			key: 'doffPersonalProductionWages',
			width: 200
		},
		{
			title: '落纱队长补贴（元）',
			dataIndex: 'doffTeamLeaderSubsidies',
			key: 'doffTeamLeaderSubsidies',
			width: 200
		},
		{
			title: '落纱系数补扣',
			dataIndex: 'doffCoefficientDeduction',
			key: 'doffCoefficientDeduction',
			width: 150
		},
		{
			title: '落纱其它补贴',
			dataIndex: 'doffOtherSubsidies',
			key: 'doffOtherSubsidies',
			width: 150
		},
		{
			title: '落纱合计工资',
			dataIndex: 'doffTotalWages',
			key: 'doffTotalWages',
			width: 150
		},
		{
			title: '摆管工资（元）',
			dataIndex: 'swingPipeWages',
			key: 'swingPipeWages',
			width: 150
		},
		{
			title: '完成率%',
			dataIndex: 'completionRate',
			key: 'completionRate',
			width: 150
		},
		{
			title: '机台保养',
			dataIndex: 'machinesMaintenance',
			key: 'machinesMaintenance',
			width: 150
		},
		{
			title: '备注',
			dataIndex: 'remark',
			key: 'remark',
			width: 150
		},
		{
			title: '操作',
			dataIndex: 'action',
			align: 'center',
			scopedSlots: {
				customRender: 'action'
			},
			fixed: 'right'
		}
	]
</script>
<style scoped>
	.body {
		background: #fff;
		padding: 15px;
	}
</style>